<?php namespace Home\Controller;
use Hdphp\Controller\Controller;
class ProtectController extends Controller{
	public function index(){
	//		获得当前商品id
	$gid=Q('get.gid',0,'intval');
	//		获得类型属性和商品属性
	$typeattribute=new \Common\Model\TypeAttribute;
	$attrdata=$typeattribute->join('goodsattribute','typeattribute_taid','=','taid')->where("goods_gid={$gid} and taclass=1")->get();
	
//商品属性
	$attr=array();
	foreach($attrdata as $k=>$v){
		$attr[$v['taid']][]=$v;
	}
	
	$attr1=array();
	foreach($attr as $k=>$v){
		foreach ($v as $ak=>$av){
			$attr1[$av['taname']][]=$av;
		}
	}
	
	View::with('attr1',$attr1);
//		sp($attr1);die;
	//	产品属性
	$typeattribute=new \Common\Model\TypeAttribute;
	$specdata=$typeattribute->join('goodsattribute','typeattribute_taid','=','taid')->where("goods_gid={$gid} and taclass=0")->get();
	$spec=array();
	foreach($specdata as $k=>$v){
		$spec[$v['taid']][]=$v;
	}
	$spec1=array();
	foreach($spec as $k=>$v){
		foreach($v as $sk=>$sv){
			$spec1[$sv['taname']][]=$sv;
		}
	}
	View::with('spec1',$spec1);
	
//		sp($spec1);die;
	//	获得商品
	$goods=new \Common\Model\Goods;
	$goodsdata=$goods->where('gid',$gid)->get();
	View::with('goodsdata',$goodsdata);
//	sp($goodsdata);die;
	//	获得产品详情
	$goodsdetial=new \Common\Model\Goodsdetail;
	$gddata=$goodsdetial->where('goods_gid',$gid)->find();
		$gddata['photo']=explode(',', $gddata['photo']);
		foreach($gddata['photo'] as $k=>$v){
			
			$gddata['php'][$k]['small']=dirname($v).'/small_'.basename($v);
			$gddata['php'][$k]['mid']=dirname($v).'/mid_'.basename($v);
			$gddata['php'][$k]['big']=dirname($v).'/big_'.basename($v);
		}
	
	
	View::with('gddata',$gddata);
//	sp($gddata);
//		sp($gddata);die;
	//	热门推荐
	$tuijian=$goods->join('category','category_cid','=','cid')->limit(5)->get();
	View::with('tuijian',$tuijian);
	//sp($tuijian);die;
		

		View::make();
	}

	//ajax
	public function Ajaxbuy(){
//		ajax方法获得所选的颜色和尺码
			$gid=Q('post.gid',0,'intval');
			$num=Q('post.num',0,'intval');
//			sp($num);die;
//			sp($gid);
			$gaid=Q('post.gaid');
			$combine=trim($gaid,',');
//			sp($gaid);sp($combine);
//			实例化货品列表
			$goodslist=new \Common\Model\Goodslists;
			$olddata=$goodslist->where("combine",$combine)->find();
//			sp($olddata);

			echo json_encode($olddata);
			exit;
		
		
		
	}











}
